<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>正则</title>
</head>
<body>
     <input type="text">
     <button>账号</button>
     <input type="text">
     <button>密码</button>
     <input type="text">
     <button>电话</button>
     <input type="text">
     <button>车牌</button>
</body>
<script>
    var but = document.getElementsByTagName("button");
    var inp = document.getElementsByTagName("input");
    var arr = [
        /^[A-z][A-z0-9_]{4,15}$/g,
        /(?=.*[a-z])(?=.*[0-9])(?=.*[A-Z])(?=.*[!|@|#])^([0-9A-Za-z!@#]{6,}$)/g,
        /^(13|15|17|18){1}\d{9}/g,
        /^[京|津|沪|渝|冀|豫|云|辽|黑|湘|皖|鲁|新|苏|浙|赣|鄂|桂|甘|晋|蒙|陕|吉|闽|贵|粤|青|藏|川|宁|琼|使|领]{1}[A-Z]{1}[A-Z0-9]{5}/g
        ];
    for (var i = 0;i < but.length;i++) { 
    (function (i) {          
            but[i].onclick = function () {
                if (inp[i].value == inp[i].value.match(arr[i])) {
                    alert("正确");
                }
                else {
                    alert("错误");
                }
            }      
    }(i))
}
</script>
</html>